/*
 * =================================================================
 *
 *       Filename:  1109.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  02/25/2011 08:23:59 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Richard Ma (richard_ma), richard.ma.19850509@gmail.com
 *        Company:  Feng Huli Primary School
 *
 * =================================================================
 */


#include	<stdlib.h>
#include	<stdio.h>
#include	<string.h>

typedef struct str_node {
    int id;
    struct str_node *next;    
} Node, *NodePtr;

/* 
 * ===  FUNCTION  ==============================================================
 *         Name:  main
 *  Description:  
 * =============================================================================
 */
    int
main ( int argc, char *argv[] )
{
    int m, n, i;
    scanf("%d %d", &n, &m);

    /* create link list */
    NodePtr head = NULL;
    NodePtr p1 = NULL, p2 = NULL;
    for (i=1; i<=n; i++) {
        p1 = malloc(sizeof(Node));
        p1->id = i;
        p1->next = NULL;

        if (head == NULL) {
            head = p2 = p1;
        } else {
            p2->next = p1;
            p2 = p1;
        }
    }
    if (head != NULL) {
        p2->next = head;
    }

    p1 = head;
    while (p1 != NULL) {
        for (i=1; i<m; i++) {
            p2 = p1;
            p1 = p1->next;
        }

        if (p1 != p1->next) {
            p2->next = p1->next;
            free(p1);
        } else {
            printf("%d\n", p1->id);
            free(p1);
            p1 = NULL;
        }
    }

    return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */

